


//1.返回顶部按钮事件
var $goTopBtn = $('.toolbar-topbtn');
$goTopBtn.click(function(){
    $('body,html').animate({ scrollTop: 0 }, 300);
})


//判断是否显示回到顶部的按钮
$(window).scroll(function(){
	winScrollFun();
});
winScrollFun();
function winScrollFun(){
	var scrolltop = $(window).scrollTop();
    if(scrolltop>0){
        $goTopBtn.css('display','block');
    }else{
        $goTopBtn.css('display','none');
    }
}


//1.1侧边栏遮挡输入框问题
toolbarinput();
function toolbarinput(){
	var $category = $('.main .search-wrap input'),
		$toolbar = $('.site-toolbar');
	
	//input focusin时隐藏toolbar
	$category.focusin(function(e){
		$toolbar.animate({
			right:'-100%'
		},300);
	});
	//input focusout时显示toolbar
	$category.focusout(function(){
		$toolbar.animate({
			right:'0.5rem'
		},300)
	});
}





//2.轮播图
if($('.site-banner').length>0){
	var $swiper_slide = $('.site-banner .swiper-slide');

	var $pagination = $('.site-banner .pagination');
		
	if($swiper_slide.length>1){
		//2.1初始化
		swiper('.site-banner');
		
		//2.1计算控制器 pagination 宽度
		var $p_switch = $('.site-banner .pagination span'),
			$p_active = $('.site-banner .swiper-pagination-bullet-active');
			
		var width = $p_active.width();
			
		var dwidth = width*($p_switch.length + 2);	
		$pagination.css('width',dwidth);
	}else{
		mySwiper('.site-banner');
		$pagination.css('display','none');
	}
}
//轮播图公共方法    初始化
function swiper(sel){
	var mySwiper = new Swiper(sel,{
		autoplay: 5000,
		speed:1000,
		loop:true,
		pagination : sel+' .pagination',
		paginationClickable :true,
		simulateTouch : false,
		autoplayDisableOnInteraction : false,
		preventClicks : false,
	});
	
	
	//控制控制器   mouseover:显示,不自动播放;   mouserout:隐藏,自动播放   
	var $banner = $(sel),
		$pagination = $(sel+' .pagination');
	$banner.mouseover(function(){
		mySwiper.stopAutoplay();
		$pagination.css('display','block');
	});
	$banner.mouseout(function(){
		mySwiper.startAutoplay();
		$pagination.css('display','none');
	});
}
//当图片小于等于一张时，不轮播
function mySwiper(sel){
	var swiper = new Swiper(sel, {
		speed:1000,
		simulateTouch : false,
    	autoplayDisableOnInteraction : false,
    	preventClicks : false,
	});
}








//3.隐藏与显示滚动条
function hiddenScroll(){
	$('body').css('overflow','hidden');
}
function overScroll(){
	$('body').css('overflow','overlay');
}